**---------------------------------------------------------------------------------
** Paper: Redistributive Preferences?
** Authors: Lars Pelke
** Contact: lars.pelke@ipw.uni-heidelberg.de
** Journal: tba
** Replication: All tables and graphs in MANUSCRIPT

cd "insert your directory here"

***-----------------------------------------------------------*****
* Import Mulitple Imputated Datasets *

use "data\income_equality_data\data1.dta", clear
mi import flongsep data_new4, using("data\income_equality_data\data1.dta" "data\income_equality_data\data2.dta" "data\income_equality_data\data3.dta" "data\income_equality_data\data4.dta" "data\income_equality_data\data5.dta" "data\income_equality_data\data6.dta" "data\income_equality_data\data7.dta" "data\income_equality_data\data8.dta" "data\income_equality_data\data9.dta" "data\income_equality_data\data10.dta") ///
 id(individual_id) imputed(education_3 unemployed income_deciles sex)
sleep 5000
mi convert mlong


***-----------------------------------------------------------*****
* Data management + 

gen dataset = 1 
replace dataset = 2 if data =="EVS"
replace dataset = 3 if data =="ESS"
replace dataset = 4 if data =="ISSP"
replace dataset = 5 if data =="Latinobarometer"

tab dataset
table(cohortmatch5_15)
table cohortmatch5_15 country_name


*center variables*

sum v2x_polyarchy, meanonly
gen v2x_polyarchy_c=v2x_polyarchy-r(mean)

sum e_migdppcln, meanonly
gen e_migdppcln_c=e_migdppcln-r(mean)


sum v2x_clphy_5, meanonly
gen v2x_clphy_5_c=v2x_clphy_5-r(mean)


sum v2exl_legitideol_5, meanonly
gen v2exl_legitideol_5_c=v2exl_legitideol_5-r(mean)

drop v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5
rename (v2x_polyarchy_c e_migdppcln_c v2x_clphy_5_c v2exl_legitideol_5_c) (v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5)


* Model 4 - repression

	set more off
	mi estimate, post: xtmixed income_equality age c.time_under_autocracy_15##c.v2x_clphy_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m4_gr
	
	
outreg2 using Output/income_equality/R3_Table2MI.doc, replace ctitle(Model 4)
outreg2 using Output/income_equality/R3_Table2MI.tex, replace ctitle(Model 4)

	
* FIGURE XX.A
 	
estimates restore m4_gr
	mimrgns ,  at(time_under_autocracy_15=(0 10 20 30 40 50 60) v2x_clphy_5=(-.6205945 0 .3334055)) atmeans cmdmargins	
	*cmdmargins is necessarcy to use marginsplots afterwards 
	marginsplot,	xlabel(0 (10) 60,  angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of Time under autocracy" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy  (at c)", size(medsmall))  ///
	legend(order(4 "-1 SD"  5 "Mean" 6 "+1 SD" ) position(12) ring(0) )  ///
	title("A. Time under Autocracy by Repression (at c) on preferences for redistribution.", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4d, replace)
	
	graph save Output/income_equality/R3_Figure1, replace
	graph export Output/income_equality/R3_Figure1.pdf, replace


	
* Model 5 - ideology

	set more off
	mi estimate, post: xtmixed  income_equality age c.time_under_autocracy_15##c.v2exl_legitideol_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m5_gr

outreg2 using Output/income_equality/R3_Table3MI.doc, replace ctitle(Model 5)
outreg2 using Output/income_equality/R3_Table3MI.tex, replace ctitle(Model 5)


* FIGURE XX.B

estimates restore m5_gr
	mimrgns ,  at(time_under_autocracy_15=(0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.923009  0  1.923009)) atmeans cmdmargins	
	marginsplot,	xlabel(0 (10) 60,  angle(horizontal)labsize(small))   ///
	ylabel(57(1)67 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of Time under autocracy" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order(4 "-1 SD"  5 "Mean" 6 "+1 SD" ) position(12) ring(0) )  ///
	title("A. Time under Autocracy by Indoctrination (at c) on preferences for redistribution.", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4e, replace)
	
	graph save Output/income_equality/R3_Figure2, replace
	graph export Output/income_equality/R3_Figure2.pdf, replace


	
* Model 6 - ideology + repression interaction

	set more off
	mi estimate, post: xtmixed  income_equality age c.time_under_autocracy_15##c.v2x_clphy_5##c.v2exl_legitideol_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m6_gr

outreg2 using Output/income_equality/R3_Table4MI.doc, replace ctitle(Model 6)
outreg2 using Output/income_equality/R3_Table4MI.tex, replace ctitle(Model 6)

 estimates restore m6_gr
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.923009  0  1.923009) v2x_clphy_5=(-.6205945 0 .3334055)) atmeans cmdmargins
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(57(1)67 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of indoctrination (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order( 4 "-1 SD"  5 "Mean" 6 "+1 SD" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
		
	graph save Output/income_equality/R3_Figure3, replace
	graph export Output/income_equality/R3_Figure3.pdf, replace

